from flask import current_app

from app.libs.httper import HTTP

class YuShuBook:
    search_by_isbn_url = "http://t.yushu.im/v2/book/search/isbn/{}"

    search_by_key_url = "http://t.yushu.im/v2/book/search?q={}&count={}&start={}"

    @classmethod
    def search_by_isbn(cls, isbn):
        url = cls.search_by_isbn_url.format(isbn)
        return HTTP.get(url)

    @classmethod
    def search_by_key(cls, keyword, page=1):
        url = cls.search_by_key_url.format(keyword, current_app.config['PER_PAGE'], (page-1)*current_app.config['PER_PAGE'])
        return HTTP.get(url)